-
Notifications
You must be signed in to change notification settings - Fork 968
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed score when using skips on non-daily habit #1713
base: dev
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No change needed in the numerical habit case?
* sum of the denominator and the number of skips within the interval. | ||
*/ | ||
@Synchronized | ||
fun getNumberOfSkipsByInterval( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really knowledgeable about this, but if you want to make it recursive, might as well follow https://kotlinlang.org/docs/functions.html#tail-recursive-functions, what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This wouldn't work here as the 'tailrec' modifier requires that the function calling itself is the last operation that function performs, which isn't the case here. I'm not really knowledgeable about this either, so I might be missing something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes but you can rewrite so that's the case, i.e. you can change the function so that it's tail-recursive. I think that'd be preferable here.
rollingSum -= 1.0 | ||
val nbOfSkips = | ||
getNumberOfSkipsByInterval(values, offset, offset + denominator) | ||
if (offset + denominator + nbOfSkips < values.size) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Create a variable for offset + denominator + nbOfSkips
to make it easier to read?
fun getNumberOfSkipsByInterval( | ||
values: IntArray, | ||
firstIndexToCheck: Int, | ||
lastIndexToCheck: Int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This parameter name is misleading, because in practice it's not necessarily the last index checked. Can you try to make it clearer for the reader what this does in which cases?
* the percentage of completed days. | ||
* | ||
* If skips are found in the interval, it is expanded until the interval has the size of the | ||
* sum of the denominator and the number of skips within the interval. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no denominator
in this function so this doc could be improved to make it understandable on its own, can you try to do that?
@@ -145,6 +146,93 @@ class YesNoScoreListTest : BaseScoreListTest() { | |||
checkScoreValues(expectedValues) | |||
} | |||
|
|||
@Test | |||
fun test_getNumberOfSkipsByInterval_NoSkips() { | |||
val vars = intArrayOf(-1, -1, -1, -1, 3, 2, 2, -1, 2, 2, -1, 2, 2, -1, 3, 2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here and below: can you hide the integer behind the enum, i.e. use SKIP
etc. instead?
@hiqua |
Requesting this fix @iSoron please. I want to properly skip a workout day for my 3 days a week workout habit but it broke my streak! |
@hiqua I've now made the function tail recursive like requested |
Could you also rebase on top of the current dev, to make it possible to run the GH actions? Thanks! |
I've rebased it! I'm not very familiar with rebasing, so I hope I did it correctly. Please let me know if I should make any more changes. |
This fixes the problems with the score raised in issue #1695 where a skip affects the score in non-daily habits, when it shouldn't.
To fix the issue, the part of the recompute function that calculates the rolling sum of completed habits in the last period was changed to take skips into account. A new function that calculates amount of skips in an interval is used to expand the length of that period.
Six tests where added, three to test the new helper function and three for testing the score.